/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.editor;

import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteEntry;
import org.eclipse.gef.ui.palette.PaletteCustomizer;
import org.eclipse.gef.ui.palette.customize.DefaultEntryPage;
import org.eclipse.gef.ui.palette.customize.DrawerEntryPage;
import org.eclipse.gef.ui.palette.customize.EntryPage;


/**
 * 
 * @author Pratik Shah
 * 
 * used by Andreas Limyr
 */
public class SeDiPaletteCustomizer extends PaletteCustomizer {

	protected static final String ERROR_MESSAGE = "SeDiPaletteCustomizer";
		
	/**
	 * @see org.eclipse.gef.ui.palette.PaletteCustomizer#getPropertiesPage(PaletteEntry)
	 */
	public EntryPage getPropertiesPage(PaletteEntry entry) {
		if (entry.getType().equals(PaletteDrawer.PALETTE_TYPE_DRAWER)) {
			return new SDDrawerEntryPage();
		}
		return new SDEntryPage();
	}
	
	/**
	 * @see org.eclipse.gef.ui.palette.PaletteCustomizer#revertToSaved()
	 */
	public void revertToSaved() {
	}
	
	
	/**
	 * @see org.eclipse.gef.ui.palette.PaletteCustomizer#dialogClosed(PaletteEntry)
	 */
	public void save() {
	}
	
	private class SDEntryPage extends DefaultEntryPage {
		protected void handleNameChanged(String text) {
			if (text.indexOf('*') >= 0) {
				getPageContainer().showProblem(ERROR_MESSAGE);
			} else {
				super.handleNameChanged(text);
				getPageContainer().clearProblem();
			}
		}
	}
	
	private class SDDrawerEntryPage extends DrawerEntryPage {
		protected void handleNameChanged(String text) {
			if (text.indexOf('*') >= 0) {
				getPageContainer().showProblem(ERROR_MESSAGE);
			} else {
				super.handleNameChanged(text);
				getPageContainer().clearProblem();
			}
		}
	}
}
